package com.shuwen.gcdj.controller.basicsstructure;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shuwen.gcdj.bean.AddResp;
import com.shuwen.gcdj.bean.DictResp;
import com.shuwen.gcdj.bean.VoidResp;
import com.shuwen.gcdj.bean.inspectionitem.requset.*;
import com.shuwen.gcdj.bean.inspectionitem.response.InspectionItemPageResp;
import com.shuwen.gcdj.bean.inspectionitem.response.InspectionPageResp;
import com.shuwen.gcdj.common.annotation.JWTAuth;
import com.shuwen.gcdj.common.api.CommonPage;
import com.shuwen.gcdj.common.api.CommonResult;
import com.shuwen.gcdj.controller.AuthController;
import com.shuwen.gcdj.service.strategyinspectionitemtemplate.StrategyInspectionitemtemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author :yys
 * 检查项管理
 * @date : 2023/5/9 17:19
 */
@Api(tags = "基础运维 - 策略管理 - 设备 - 检查项")
@RestController
@RequestMapping("/inspectionitem")
@Slf4j
public class InspectionitemController extends AuthController {

    @Autowired
    private StrategyInspectionitemtemplateService strategyInspectionitemtemplateService;

    @ApiOperation(value = "获取检查项模板库分页信息")
    @PostMapping(value = "/getinspectionitemtamplatepage")
    @ResponseBody
    @JWTAuth
    public CommonResult<CommonPage<InspectionItemPageResp>> getThirdStructurePage(@RequestBody InspectionItemPageReq req) {
        Page<InspectionItemPageResp> list = strategyInspectionitemtemplateService.getThirdStructurePage(req);
        return CommonResult.success(CommonPage.restPage(list));
    }

    @ApiOperation(value = "获取检查项模板库列表信息")
    @PostMapping(value = "/getinspectionitemtamplate")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<InspectionItemPageResp>> getinspectionitemtamplate() {
        List<InspectionItemPageResp> list = strategyInspectionitemtemplateService.getinspectionitemtamplate();
        return CommonResult.success(list);
    }


    @ApiOperation(value = "添加检查项模板")
    @PostMapping(value = "/addstrategyinspectionitemtemplate")
    @ResponseBody
    @JWTAuth
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<AddResp> addTemplate(HttpServletRequest request, @Valid @RequestBody AddTemplateReq req) {
        AddResp addResp = strategyInspectionitemtemplateService.addTemplate(initUser(request),req);
        return CommonResult.success(addResp);
    }

    @ApiOperation(value = "修改检查项模板状态")
    @PostMapping(value = "/edittemplatestate")
    @ResponseBody
    @JWTAuth
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<VoidResp> edittemplatestate(HttpServletRequest request, @Valid @RequestBody CheckStateReq req) {
        VoidResp voidResp = strategyInspectionitemtemplateService.edittemplatestate(initUser(request),req);
        return CommonResult.success(voidResp);
    }

    @ApiOperation(value = "批量删除检查项模板")
    @PostMapping(value = "/batchdeletetemplate")
    @ResponseBody
    @JWTAuth
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<VoidResp> batchTemplate(HttpServletRequest request,@RequestBody DeleteTemplateReq req) {
        VoidResp voidResp = strategyInspectionitemtemplateService.batchTemplate(initUser(request),req);
        return CommonResult.success(voidResp);
    }


    @ApiOperation(value = "获取检查项列表分页信息(头部信息从上一个页面带过来)")
    @PostMapping(value = "/getinspectionitempagebytemplate")
    @ResponseBody
    @JWTAuth
    public CommonResult<CommonPage<InspectionPageResp>> getinspectionitempagebytemplate(@RequestBody InspectionPageReq req) {
        Page<InspectionPageResp> page = strategyInspectionitemtemplateService.getinspectionitempagebytemplate(req);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation(value = "获取检查项列表信息")
    @PostMapping(value = "/getinspectionitembytemplate")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<InspectionPageResp>> getinspectionitembytemplate(@Valid @RequestBody InspectionPageReq req) {
        List<InspectionPageResp> page = strategyInspectionitemtemplateService.getinspectionitembytemplate(req);
        return CommonResult.success(page);
    }

    @ApiOperation(value = "批量新增检查项")
    @PostMapping(value = "/batchaddinspectionitem")
    @ResponseBody
    @JWTAuth
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<List<AddResp>> batchaddinspectionitem(HttpServletRequest request,@RequestBody BatchAddInspectionReq req) {
        List<AddResp> addResp = strategyInspectionitemtemplateService.batchaddinspectionitem(initUser(request),req);
        return CommonResult.success(addResp);
    }

    @ApiOperation(value = "批量删除检查项")
    @PostMapping(value = "/batchdeleteinspectionitem")
    @ResponseBody
    @JWTAuth
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<VoidResp> batchdeleteinspectionitem(HttpServletRequest request,@RequestBody DeleteTemplateReq req) {
        VoidResp voidResp = strategyInspectionitemtemplateService.batchdeleteinspectionitem(initUser(request),req);
        return CommonResult.success(voidResp);
    }

    @ApiOperation(value = "编辑检查项")
    @PostMapping(value = "/editinspectionitem")
    @ResponseBody
    @JWTAuth
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<VoidResp> editinspectionitem(HttpServletRequest request,@RequestBody InspectionPamas req) {
        VoidResp voidResp = strategyInspectionitemtemplateService.editinspectionitem(initUser(request),req);
        return CommonResult.success(voidResp);
    }

    @ApiOperation(value = "获取三级部件")
    @GetMapping(value = "/getthirdstructurelist")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getthirdstructurelist() {
        List<DictResp> list = strategyInspectionitemtemplateService.getthirdstructurelist();
        return CommonResult.success(list);
    }

    @ApiOperation(value = "获取检查项模板列表")
    @GetMapping(value = "/getinspectionitemtemplatelist")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getinspectionitemtemplatelist() {
        List<DictResp> list = strategyInspectionitemtemplateService.getinspectionitemtemplatelist();
        return CommonResult.success(list);
    }

    @ApiOperation(value = "获取检查项检查结果")
    @GetMapping(value = "/getinspectioniteminspectionresultlist")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getinspectioniteminspectionresultlist() {
        List<DictResp> list = strategyInspectionitemtemplateService.getinspectioniteminspectionresultlist();
        return CommonResult.success(list);
    }

    @ApiOperation(value = "获取检查项处置方式")
    @GetMapping(value = "/getinspectionitemdisposalmethodlist")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getinspectionitemdisposalmethodlist() {
        List<DictResp> list = strategyInspectionitemtemplateService.getinspectionitemdisposalmethodlist();
        return CommonResult.success(list);
    }


}
